Re: [GENERAL] Incrementing a Serial Field - Mailing list pgsql-general

From Herouth Maoz
Subject Re: [GENERAL] Incrementing a Serial Field
Date
Msg-id l03110701b26cc8f67da9@[147.233.159.109]
Whole thread Raw
In response to Incrementing a Serial Field  (Bob Kruger <bkruger@mindspring.com>)
List pgsql-general
At 19:07 +0200 on 9/11/98, Bob Kruger wrote:


>
> I do have two questions.  Firstly, I have one table that is updated from a
> text file.  This table also has a serial field that is incremented with
> each new record.  Is there a way to use the copy command to have that field
> automatically updated - e.g. copy table_one from '/data/files/input.txt'
> using delimiters '|' ?
>
> So far, I can get this text file to import just fine when using a table
> without a serial field, but as of yet not had any luck in importing it into
> a table that has a serial field.

Assuming the serial field is defined as a NOT NULL DEFAULT nextval( 'seq'
), the simplest way is to put nulls for that field in the text file. That
is, suppose it is the third field in your table, you write

data for field1|data for field 2|\N|data for field4...

The \N (capital N) stands for null, and will cause Postgres to use the
default value for that field.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-general by date:

Previous
From: Ulf Mehlig
Date:
Subject: Re: [GENERAL] Case insensitive "contains" search
Next
From: "Gene Selkov, Jr."
Date:
Subject: is NULL = NULL true or false?